//
//  YZInfoColorBgCell.m
//  shadow
//
//  Created by Pro on 2022/1/13.
//

#import "YZInfoColorBgCell.h"
#define yz_width  414 / 2;
#define yz_height 30

@interface YZInfoColorBgCell()
@property(nonatomic,strong)UIView * leftInfoView;
@property(nonatomic,strong)UILabel * left1Label;
@property(nonatomic,strong)UILabel * left2Label;
@property(nonatomic,strong)UILabel * right1Label;
@property(nonatomic,strong)UILabel * right2Label;
//@property(nonatomic,strong)CALayer * leftLayer;
//@property(nonatomic,strong)CALayer * rightLayer;
@property(nonatomic,strong)UIView * rightInfoView;


@end

@implementation YZInfoColorBgCell

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *identifier = @"YZInfoColorBgCell";
    // 1.缓存中取
    YZInfoColorBgCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    // 2.创建
   if (cell == nil) {
        cell = [[YZInfoColorBgCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;

}
/**
 *  构造方法(在初始化对象的时候会调用)
 *  一般在这个方法中添加需要显示的子控件
 */
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubview:self.leftInfoView];
        
        [self addSubview:self.rightInfoView];
    }
    return self;
}




- (void)setDictionary:(NSDictionary *)dictionary {
    _dictionary = dictionary;
    NSInteger leftp = arc4random() % 100;
    NSInteger rightp = arc4random() % 100;
    NSString * left1 = dictionary[@"left1"];
    NSString * left2 = dictionary[@"left2"];
//    NSString * leftp = dictionary[@"leftp"];
    double leftpd = leftp  / 100.0;
    NSString * right1 = dictionary[@"right1"];
    NSString * right2 = dictionary[@"right2"];
//    NSString * rightp = dictionary[@"rightp"];
    double rightpd = rightp / 100.0;

    self.left1Label.text = left1;
    self.left2Label.text = left2;
    self.right1Label.text = right1;
    self.right2Label.text = right2;
    self.leftInfoView.layer.shadowOpacity = 0.5;
    self.leftInfoView.layer.masksToBounds = NO;
    self.leftInfoView.layer.shadowOffset = CGSizeMake(0, 0);
    self.leftInfoView.layer.shadowRadius = 0;
    self.leftInfoView.layer.shadowColor = [[UIColor greenColor] colorWithAlphaComponent:0.8].CGColor;
    
    CGMutablePathRef squarePath = CGPathCreateMutable();
    CGPathAddRect(squarePath, NULL, CGRectMake(207 - 207 * leftpd, 0, 207 * leftpd, yz_height));
    
    self.leftInfoView.layer.shadowPath = squarePath;
    CGPathRelease(squarePath);
    
    self.rightInfoView.layer.shadowOpacity = 0.5;
    self.rightInfoView.layer.masksToBounds = NO;
    self.rightInfoView.layer.shadowOffset = CGSizeMake(0, 0);
    self.rightInfoView.layer.shadowRadius = 0;
    self.rightInfoView.layer.shadowColor = [[UIColor redColor] colorWithAlphaComponent:0.1].CGColor;
    CGMutablePathRef squarePath1 = CGPathCreateMutable();
    CGPathAddRect(squarePath1, NULL, CGRectMake(0, 0, 414 / 2 * rightpd, yz_height));
    self.rightInfoView.layer.shadowPath = squarePath1;
    CGPathRelease(squarePath1);
    
//    self.leftLayer.frame = CGRectMake(207 - 207 * leftpd, 0, 207 * leftpd, yz_height);
//    self.rightLayer.frame = CGRectMake(0, 0, 414 / 2 * rightpd, yz_height);
    
}

-(UIView *)leftInfoView {
    if (_leftInfoView == nil) {
        _leftInfoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 414 / 2, yz_height)];
//        _leftInfoView.backgroundColor = [UIColor greenColor];
//        [_leftInfoView.layer addSublayer:self.leftLayer];

        [_leftInfoView addSubview:self.left1Label];
        [_leftInfoView addSubview:self.left2Label];
    }
    return _leftInfoView;
}

-(UIView *)rightInfoView {
    if (_rightInfoView == nil) {
        _rightInfoView = [[UIView alloc] initWithFrame:CGRectMake(414 / 2, 0, 414 / 2 , yz_height)];
//        _rightInfoView.backgroundColor = [UIColor redColor];
//        [_rightInfoView.layer addSublayer:self.rightLayer];

        [_rightInfoView addSubview:self.right1Label];
        [_rightInfoView addSubview:self.right2Label];
    }
    return _rightInfoView;
}

-(UILabel *)left1Label {
    if (_left1Label == nil) {
        _left1Label = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, 80, yz_height)];
        _left1Label.textAlignment = NSTextAlignmentLeft;
        _left1Label.font = [UIFont systemFontOfSize:14];
        _left1Label.textColor = [UIColor blackColor];
    }
    return _left1Label;
}

-(UILabel *)left2Label {
    if (_left2Label == nil) {
        _left2Label = [[UILabel alloc] initWithFrame:CGRectMake(414 / 2 - 80 - 5, 0, 80, yz_height)];
        _left2Label.textAlignment = NSTextAlignmentRight;
        _left2Label.font = [UIFont systemFontOfSize:14];
        _left2Label.textColor = [UIColor blueColor];
    }
    return _left2Label;
}

-(UILabel *)right1Label {
    if (_right1Label == nil) {
        _right1Label = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, 80, yz_height)];
//        _right1Label.text = @"label.text";
        _right1Label.textAlignment = NSTextAlignmentLeft;
        _right1Label.font = [UIFont systemFontOfSize:14];
        _right1Label.textColor = [UIColor redColor];
    }
    return _right1Label;
}

-(UILabel *)right2Label {
    if (_right2Label == nil) {
        _right2Label = [[UILabel alloc] initWithFrame:CGRectMake(414 / 2  - 80 - 5, 0, 80, yz_height)];
//        _right2Label.text = @"label.text";
        _right2Label.textAlignment = NSTextAlignmentRight;
        _right2Label.font = [UIFont systemFontOfSize:14];
        _right2Label.textColor = [UIColor blackColor];
    }
    return _right2Label;
}

//-(CALayer *)leftLayer {
//    if (_leftLayer == nil) {
//        _leftLayer = [[CALayer alloc] init];
//        _leftLayer.backgroundColor = [[UIColor greenColor] colorWithAlphaComponent:0.1].CGColor;
//    }
//    return _leftLayer;
//}

//-(CALayer *)rightLayer {
//    if (_rightLayer == nil) {
//        _rightLayer = [[CALayer alloc] init];
//        _rightLayer.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.1].CGColor;
//    }
//    return _rightLayer;
//}




@end

